open(BUFF,"gunzip -c ambi.gz |") or die " no file found ambi.gz\n";
while(<BUFF>)
{
	chomp($_);
	@array=split(" ",$_);
	$hash{$array[1]}="$array[1]";
}
open(BUFF,"gunzip -c beagle.r2.ambi.gz |") or die " no file found beagle.r2.ambi.gz\n";
while(<BUFF>)
{
	chomp($_);
	@array=split("\t",$_);	
	if(exists($hash{$array[0]}))
	{
		$hash{$array[0]} = $hash{$array[0]}."\t".$array[4];
	}
}
open(BUFF,"gunzip -c beagle.r2_2step_ambi.gz |") or die " no file found beagle.r2.ambi.gz\n";
while(<BUFF>)
{
        chomp($_);
        @array=split("\t",$_);
        if(exists($hash{$array[0]}))
        {
                $hash{$array[0]} = $hash{$array[0]}."\t".$array[4];
        }
}
open(WRBUFF,">SNP_DOSAGE_AMBI_2STEPAMBI");
print WRBUFF "SNP\tDOSAGE_R2_AMBI\tDOSAGE_R2_2STEP_AMBI\n";
while(my($key,$value)=each %hash)
{
	print WRBUFF "$value\n";
}
